<template>
<!-- <div>弃用</div> -->
    <el-dialog
        :title="!dataForm.id ? $t('handle.add') : $t('handle.update')"
        :close-on-click-modal="false"
        :visible.sync="visible">
        <el-tabs v-model="activeName" @tab-click="handleClick">
            <!--人员基础信息-->
            <el-tab-pane label="人员基础信息" name="first" >
                <el-form :model="dataForm" :rules="dataRule" ref="dataForm"  label-width="150px">
                    <el-row :gutter="24">
                        <el-col :span="12">
                            <el-form-item label="户主姓名" prop="householderName">
                                <el-input v-model="dataForm.householderName" placeholder="户主姓名" @click.native="selectPersonne()"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="头像">
                                <el-popover
                                    placement="right"
                                    title=""
                                    trigger="hover">
                                    <img :src="dataForm.image"/>
                                    <img slot="reference" :src="dataForm.image"  style="max-height: 50px;max-width: 130px">
                                </el-popover>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="12">
                            <el-form-item label="身份证号" prop="identityCard">
                                <el-input v-model="dataForm.identityCard" placeholder="身份证号" ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="联系电话" prop="contactPhone">
                                <el-input v-model="dataForm.contactPhone" placeholder="联系电话" ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="24">
                            <el-form-item label="所属房间号">
                                <el-cascader style="width:100%;" v-model="roomAddress" ref="room" :options="roomOptions" @active-item-change="getRoom" :props="roomProps"></el-cascader>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="12">
                            <el-form-item :label="$t('form.birthDate')" prop="birthdate">
                                <el-date-picker
                                    v-model="dataForm.birthdate"
                                    type="datetime"
                                    placeholder="选择日期时间"
                                    value-format="yyyy-MM-dd HH:mm:ss"
                                    style="width: 100%;">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="与户主关系" prop="relationsWithHouseholds">
                                <el-select style="width: 100%;" v-model="dataForm.relationsWithHouseholds" filterable placeholder="请选择">
                                    <el-option v-for="item in householdDicts" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="12">
                            <el-form-item :label="$t('form.sex')" prop="gender">
                               <el-select style="width: 100%;" v-model="dataForm.gender" filterable placeholder="请选择">
                                    <el-option v-for="item in sexDicts" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="民族" prop="nation">
                                <el-select style="width: 100%;" v-model="dataForm.nation" filterable placeholder="请选择">
                                    <el-option v-for="item in nation" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="12">
                            <el-form-item label="真实姓名" prop="realName">
                                <el-input v-model="dataForm.realName" placeholder="真实姓名" ></el-input>
                            </el-form-item>

                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="房东姓名" prop="landlordName">
                                <el-input v-model="dataForm.landlordName" placeholder="房东姓名" ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="12">
                            <el-form-item label="房东电话" prop="landlordPhone">
                                <el-input v-model="dataForm.landlordPhone" placeholder="房东电话" ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="婚姻状况" prop="maritalStatus">
                                <el-select style="width: 100%;" v-model="dataForm.maritalStatus" filterable placeholder="请选择">
                                    <el-option v-for="item in maritalDicts" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="12">
                            <el-form-item label="结婚日期" prop="weddingDay">
                                <el-date-picker
                                    v-model="dataForm.weddingDay"
                                    type="datetime"
                                    placeholder="选择日期时间"
                                    value-format="yyyy-MM-dd HH:mm:ss"
                                    style="width: 100%;">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="户口性质" prop="accountProperties">
                                <el-select style="width: 100%;" v-model="dataForm.accountProperties" filterable placeholder="请选择">
                                    <el-option v-for="item in accountPropertiesDicts" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="12">
                            <el-form-item label="户籍地说明" prop="domicileAddress">
                                <el-input v-model="dataForm.domicileAddress" placeholder="户籍地说明" ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="租用日期" prop="letDate">
                                <el-input v-model="dataForm.letDate" placeholder="租用日期" ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="12">
                            <el-form-item label="健康状况" prop="healthCondition">
                                <el-select style="width: 100%;" v-model="dataForm.healthCondition" filterable placeholder="请选择">
                                    <el-option v-for="item in healthDicts" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="文化程度" prop="educationDegree">
                                <el-select style="width: 100%;" v-model="dataForm.educationDegree" filterable placeholder="请选择">
                                    <el-option v-for="item in educationDicts" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                             </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="12">
                            <el-form-item label="是否独生" prop="isOnly">
                                <el-select style="width: 100%;" v-model="dataForm.isOnly" filterable placeholder="请选择">
                                    <el-option v-for="item in isOnlyDicts" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="职业" prop="occupation">
                                <el-select style="width: 100%;" v-model="dataForm.occupation" filterable placeholder="请选择">
                                    <el-option v-for="item in occupationDicts" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="12">
                            <el-form-item label="工作单位" prop="workUnit">
                                <el-input v-model="dataForm.workUnit" placeholder="工作单位" ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="是否同户" prop="isWithDoor">
                                <el-select style="width: 100%;" v-model="dataForm.isWithDoor" filterable placeholder="请选择">
                                    <el-option v-for="item in isWithDoorDicts" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="12">
                            <el-form-item label="是否党员" prop="isPartyMember">
                                <el-select style="width: 100%;" v-model="dataForm.isPartyMember" filterable placeholder="请选择">
                                    <el-option v-for="item in isPartyMemberDicts" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="是否低保人员" prop="isSubsistenceAllowance">
                                <el-select style="width: 100%;" v-model="dataForm.isSubsistenceAllowance" filterable placeholder="请选择">
                                    <el-option v-for="item in subsistenceAllowanceDicts" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="12">
                            <el-form-item label="是否重点人员" prop="isFocusGroups">
                                <el-select style="width: 100%;" v-model="dataForm.isFocusGroups" filterable placeholder="请选择">
                                    <el-option v-for="item in isFocusGroupsDicts" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="是否缴纳养老保险" prop="isEndowmentInsurance">
                                <el-select style="width: 100%;" v-model="dataForm.isEndowmentInsurance" filterable placeholder="请选择">
                                    <el-option v-for="item in endowmentInsuranceDicts" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="12">
                            <el-form-item label="残疾类型" prop="disabilityType">
                                <el-select style="width: 100%;" v-model="dataForm.disabilityType" filterable placeholder="请选择">
                                    <el-option v-for="item in disabilityTypeDixts" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="残疾证号" prop="disabilityNumber">
                                <el-input v-model="dataForm.disabilityNumber" placeholder="残疾证号" style="width: 100%;"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="12">
                            <el-form-item label="是否现服兵役" prop="isNowMilitaryService">
                                <el-select style="width: 100%;" v-model="dataForm.isNowMilitaryService" filterable placeholder="请选择">
                                    <el-option v-for="item in nowMilitaryServiceDicts" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="是否空巢/孤寡" prop="isEmptyNest">
                                <el-select style="width: 100%;" v-model="dataForm.isEmptyNest" filterable placeholder="请选择">
                                    <el-option v-for="item in emptyNestDicts" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row style="float : right;">
                        <el-button @click="callOf()">{{ $t('handle.cancel') }}</el-button>
                        <el-button  type="primary" @click="dataFormSubmit()">提交</el-button>
                    </el-row>
                </el-form>
            </el-tab-pane>
        </el-tabs>
        <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @infoMess="getByInfo" @refreshDataList="getDataList()"></add-or-update>
    </el-dialog>
</template>
<script>
import AddOrUpdate from './selectPerson'
import {isMobile} from '@/utils/validate'
import {cardid} from '@/utils/validate'
export default {
    data(){
        // 手机号验证
        var validateMobile = (rule, value, callback) => {
            if (!isMobile(value)) {
            callback(new Error('手机号格式错误'))
            } else {
            callback()
            }
        }
        var ValidateCardId = (rule, value, callback)=>{
            if(cardid(value)[0]){
                callback(new Error('身份证格式错误'))
            }else{
                callback()
            }
        }
        return {
            sexDicts: [],
            nation: [],
            genderOptions: {
                label: '',
                value: ''
            },
            nationOptions: {
                label: '',
                value: ''
            },
            addOrUpdateVisible: false,
            visible: false,
            roomAddress: [],
            roomOptions: [],
            roomProps: {
                label: 'name',
                value: 'id',
                children: "children"
            },
            buildingId: '',
            householdDicts: [],
            genderDicts: [],
            nationDicts: [],
            maritalDicts: [],
            accountPropertiesDicts: [],
            healthDicts: [],
            educationDicts: [],
            isOnlyDicts: [],
            occupationDicts: [],
            isWithDoorDicts: [],
            isPartyMemberDicts: [],
            subsistenceAllowanceDicts:[],
            isFocusGroupsDicts: [],
            endowmentInsuranceDicts: [],
            disabilityTypeDixts: [],
            nowMilitaryServiceDicts: [],
            emptyNestDicts: [],
            emptyNestDicts: [],
            womanManDicts: [],
            // womanManDictType:{1:'男方'},
            kinshipDicts: [],
            // 基础信息
            dataForm:{
                id: '',
                householderName: '',
                contactPhone: '',
                houseAddress: '',
                griddingId: '',
                landlordName: '',
                landlordPhone: '',
                roomId: '',
                realName: '',
                letDate: '',
                relationsWithHouseholds: '',
                gender: '',
                nation: '',
                birthdate: '',
                maritalStatus: '',
                weddingDay: '',
                accountProperties:'',
                domicileAddress: '',
                identityCard: '',
                healthCondition: '',
                educationDegree: '',
                isOnly: '',
                occupation: '',
                workUnit: '',
                isWithDoor: '',
                isPartyMember: '',
                isSubsistenceAllowance: '',
                isFocusGroups: '',
                isEndowmentInsurance: '',
                disabilityType: '',
                disabilityNumber: '',
                isNowMilitaryService: '',
                isEmptyNest:'',
                image: ''
           },
           // 子女信息
           childDataForm: {
                id: '',
                personnelBasicId: '',
                womanMan: '',
                childOrder: '',
                policyAttributes: '',
                kinship: ''
           },
           changeDataForm: {
               personnelName: '',

           },

           // 默认选中第一个选项卡
           activeName: 'first',
            // 基础信息验证
            dataRule: {
                householderName: [
                    {required: true, message: '姓名不能为空', trigger: 'blur'}
                ],
                roomId: [
                    {required: false, message: '房间不能为空', trigger: 'change'}
                ],
                contactPhone: [
                    { required: true, message: '联系电话不能为空', trigger: 'blur' },
                    { validator: validateMobile, trigger: 'blur' }
                ],
                landlordName: [
                    {required: false, message: '房东姓名不能为空', trigger: 'blur'}
                ],
                landlordPhone: [
                    { required: false, message: '房东电话不能为空', trigger: 'blur' },
                    // { validator: validateMobile, trigger: 'blur' }
                ],
                realName: [
                    {required: true, message: '真实姓名不能为空', trigger: 'blur'}
                ],
                identityCard: [
                   {required: true, message: '身份证号不能为空',trigger: 'blur'},
                   {validator: ValidateCardId, trigger: 'blur'}
                ],
                relationsWithHouseholds: [
                    {required: true, message: '与户主不能为空', trigger: 'blur'}
                ],
                gender: [
                    {required: true, message: '性别不能为空', trigger: 'blur'}
                ],
                nation: [
                    {required: true, message: '民族不能为空', trigger: 'blur'}
                ],
                birthdate:[
                    {required: true, message: '出生日期不能为空', trigger: 'blur'}
                ],
                maritalStatus: [
                     {required: false, message: '婚姻状况不能为空', trigger: 'blur'}
                ],
                accountProperties: [
                    {required: false, message: '户口性质不能为空', trigger: 'blur'}
                ],
                domicileAddress: [
                    {required: false, message: '户籍地说明不能为空', trigger: 'blur'}
                ],
                healthCondition: [
                    {required: false, message: '健康状况不能为空', trigger: 'blur'}
                ],
                educationDegree: [
                    {required: false, message: '文化程度不能为空', trigger: 'blur'}
                ],
                isOnly: [
                    {required: false, message: '是否独生不能为空', trigger: 'blur'}
                ],
                occupation: [
                    {required: false, message: '职业不能为空', trigger: 'blur'}
                ],
                workUnit: [
                    {required: false, message: '工作单位不能为空', trigger: 'blur'}
                ],
                isWithDoor: [
                    {required: false, message: '是否同户不能为空', trigger: 'blur'}
                ],
                isPartyMember: [
                    {required: false, message: '是否党员不能为空', trigger: 'blur'}
                ],
                isSubsistenceAllowance: [
                    {required: false, message: '是否低保人员不能为空', trigger: 'blur'}
                ],
                isFocusGroups: [
                    {required: false, message: '是否重点人员不能为空', trigger: 'blur'}
                ],
                isEndowmentInsurance: [
                     {required: false, message: '是否缴纳养老保险不能为空', trigger: 'blur'}
                ],
                isNowMilitaryService: [
                    {required: false, message: '是否现服兵役不能为空', trigger: 'blur'}
                ],
                isEmptyNest: [
                    {required: false, message: '是否空巢/孤老不能为空', trigger: 'blur'}
                ]
            },
            // 子女信息验证
            ChildDataRule: {

            },
            // 变更信息验证
            ChangeDataRule: {

            }
        }
    },
    components: {
      AddOrUpdate
    },
    computed: {

    },
    created(){
        // 获取字典
        this.getWomanMan()
        this.getKinship()
    },
    mounted: function(){
        // 获取所有房间
        this.getGenner()
        this.getNation()
        this.getCountry()
    },
    methods:{
        getRoom(val){
            if(val.length === 1){
                this.getProvice(val[0])
            }else if(val.length === 2){
                this.getCity(val[0],val[1])
            }else if(val.length === 3){
                this.getArea(val[0],val[1],val[2])
            }else if(val.length === 4){
                this.getCommunty(val[0],val[1],val[2],val[3])
            }else if(val.length === 5){
                this.getHousing(val[0],val[1],val[2],val[3],val[4])
            }else if(val.length === 6){
                this.getBuild(val[0],val[1],val[2],val[3],val[4],val[5])
            }else if(val.length === 7){
                this.getRooms(val[0],val[1],val[2],val[3],val[4],val[5],val[6])
            }
        },
        getCountry(){
            this.$http({
                url: `/dg-standard-info/dgstandardaddress/childlistbyparentandtype`,
                method: 'post',
                params:{parentId: 0,type:11}
            }).then(({data})=>{
                if(data && data.code === 0){
                    data.data.map(item => {
                        this.$set(item, "name", item.name);
                        this.$set(item, "children", []);
                    });
                    this.roomOptions = data.data

                }
            })
        },
        getProvice(countryId){
            this.$http({
                url: `/dg-standard-info/dgstandardaddress/childlistbyparentandtype`,
                method: 'post',
                params:{parentId: countryId,type:12}
            }).then(({data})=>{
                if(data && data.code === 0){
                    data.data.map(item => {
                        this.$set(item, "name", item.name);
                        this.$set(item, "children", []);
                    });
                   this.roomOptions.map(item=>{
                       if(item.id === countryId){
                           item.children = data.data
                       }
                   })
                }
            })
        },
        getCity(countryId,provinceId){
            this.$http({
                url: `/dg-standard-info/dgstandardaddress/childlistbyparentandtype`,
                method: 'post',
                params:{parentId: provinceId,type:13}
            }).then(({data})=>{
                if(data && data.code === 0){
                    data.data.map(item => {
                        this.$set(item, "name", item.name);
                        this.$set(item, "children", []);
                    });
                   this.roomOptions.map((item, i) => {
                        if (item.id === countryId) {
                            item.children.map((city, id) => {
                                 city.children = data.data;
                            });
                        }
                    });
                }
            })
        },
        getArea(countryId,provinceId,cityId){
            this.$http({
                url: `/dg-standard-info/dgstandardaddress/childlistbyparentandtype`,
                method: 'post',
                params:{parentId: cityId,type:31}
            }).then(({data})=>{
                if(data && data.code === 0){
                    data.data.map(item => {
                        this.$set(item, "name", item.name);
                        this.$set(item, "children", []);
                    });
                    this.roomOptions.map((item, i) => {
                        if (item.id === countryId) {
                        item.children.map((provice, idx) => {
                            if(provice.id === provinceId){
                                provice.children.map((city, ids) => {
                                    city.children = data.data
                                });
                            }
                        });
                        }
                    });
                }

            })
        },
        getCommunty(countryId,provinceId,cityId,areaId){
            this.$http({
                url: `/dg-standard-info/dgstandardaddress/childlistbyparentandtype`,
                method: 'post',
                params:{parentId: areaId,type:32}
            }).then(({data})=>{
                if(data && data.code === 0){
                    data.data.map(item => {
                        this.$set(item, "name", item.name);
                        this.$set(item, "children", []);
                    });
                    this.roomOptions.map((item, i) => {
                        if (item.id === countryId) {
                        item.children.map((provice, idx) => {
                            if(provice.id === provinceId){
                                provice.children.map((city, ids) => {
                                  if(city.id === cityId){
                                    city.children.map((area,aid)=>{
                                      area.children =data.data
                                    })
                                  }
                                });
                            }
                        });
                        }
                    });
                }
            })
        },
        getHousing(countryId,provinceId,cityId,areaId,communityCodeId){
            this.$http({
                url: `/dg-ic/ic/housing-estate/getByCommuntId/${communityCodeId}`,
                method: 'get'
            }).then(({data})=>{
                if(data && data.code === 0){
                    data.data.map(item => {
                        this.$set(item, "name", item.name);
                        this.$set(item, "children", []);
                    });
                    this.roomOptions.map((item, i) => {
                        if (item.id === countryId) {
                        item.children.map((provice, idx) => {
                            if(provice.id === provinceId){
                                provice.children.map((city, ids) => {
                                    if(city.id === cityId){
                                        city.children.map((area,aid)=>{
                                            if(area.id === areaId){
                                                area.children.map((communt,ic)=>{
                                                    communt.children = data.data
                                                })
                                            }
                                        })
                                    }
                                });
                            }
                        });
                        }
                    });
                }

            })
        },
        getBuild(countryId,provinceId,cityId,areaId,communityCodeId,housId){
            this.$http({
                url: `/dg-ic/ic/building/getByHousing/${housId}`,
                method: 'get'
            }).then(({data})=>{
                if(data && data.code === 0){
                    data.data.map(item => {
                        this.$set(item, "name", item.name);
                        this.$set(item, "children", []);
                    });
                    this.roomOptions.map((item, i) => {
                        if (item.id === countryId) {
                        item.children.map((provice, idx) => {
                            if(provice.id === provinceId){
                                provice.children.map((city, ids) => {
                                    if(city.id === cityId){
                                        city.children.map((area,aid)=>{
                                            if(area.id === areaId){
                                                area.children.map((communt,ic)=>{
                                                    if(communt.id === communityCodeId){
                                                        communt.children.map((house,iu)=>{
                                                           house.children = data.data
                                                        })
                                                    }
                                                })
                                            }
                                        })
                                    }
                                });
                            }
                        });
                        }
                    });
                }

            })
        },
        getRooms(countryId,provinceId,cityId,areaId,communityCodeId,housId,buildId){
            this.$http({
                url: `/dg-ic/ic/room/getByBuilding/${buildId}`,
                method: 'get'
            }).then(({data})=>{
                if(data && data.code === 0){
                    data.data.map(item => {
                        this.$set(item, "name", item.name);
                        // this.$set(item, "children", []);
                    });
                    this.roomOptions.map((item, i) => {
                        if (item.id === countryId) {
                        item.children.map((provice, idx) => {
                            if(provice.id === provinceId){
                                provice.children.map((city, ids) => {
                                    if(city.id === cityId){
                                        city.children.map((area,aid)=>{
                                            if(area.id === areaId){
                                                area.children.map((communt,ic)=>{
                                                    if(communt.id === communityCodeId){
                                                        communt.children.map((house,iu)=>{
                                                           if(house.id === housId){
                                                               house.children = data.data
                                                           }
                                                        })
                                                    }
                                                })
                                            }
                                        })
                                    }
                                });
                            }
                        });
                        }
                    });
                }

            })
        },
        // 获取人口的基本信息并回显
        getByInfo(id,sexDicts,nation,image){
            this.sexDicts = sexDicts
            this.nation = nation
            this.dataForm.image = image
            this.$http({
                url: `/dg-standard-info/standardinfo/dgactualpopulation/info/${id}`,
                method: 'get',
                params: this.$http.adornParams()
            }).then(({data})=>{
                if(data && data.code === 0){
                    this.dataForm.householderName = data.dgActualPopulation.name
                    this.dataForm.identityCard = data.dgActualPopulation.identificationNumber
                    this.dataForm.birthdate = data.dgActualPopulation.birthdate.toString()
                    this.dataForm.gender = data.dgActualPopulation.sex
                    this.dataForm.nation = data.dgActualPopulation.nation



                }
            })
        },
        selectPersonne(){
            this.addOrUpdateVisible = true
            this.$nextTick(()=>{
                this.$refs.addOrUpdate.init()
            })
        },
        // 判断该房间下是否有户主
        decideRoom(){
            this.$http({
                url: `/dg-ic/ic/room/decideRoom/${this.dataForm.roomId}`,
                method: 'get',
                params: this.$http.adornParams()
            }).then(({data})=>{
                if(data && data.code === 0){
                    if(data.data === false){
                        // 没有户主
                        this.$message({
                            message: '该房间下还没有户主，请先录入户主信息',
                            type: 'warning',
                            duration: 1500,
                            onClose: () => {

                            }
                        })

                    }else{
                        // 有户主

                    }
                }
            })
        },
        handleClick(tab,event){
           if(tab.index === '0'){
               this.init()
           }
       },
        init(id,householdDicts,maritalDicts,accountPropertiesDicts,healthDicts,
        educationDicts,isOnlyDicts,occupationDicts,isWithDoorDicts,isPartyMemberDicts,subsistenceAllowanceDicts,
        isFocusGroupsDicts,endowmentInsuranceDicts,disabilityTypeDixts,nowMilitaryServiceDicts,emptyNestDicts){
            this.show = true
            this.visible = true
            this.dataForm.id = id || 0
            this.householdDicts = householdDicts
            this.maritalDicts = maritalDicts
            this.accountPropertiesDicts = accountPropertiesDicts
            this.healthDicts = healthDicts
            this.educationDicts = educationDicts
            this.isOnlyDicts = isOnlyDicts
            this.occupationDicts = occupationDicts
            this.isWithDoorDicts = isWithDoorDicts
            this.isPartyMemberDicts = isPartyMemberDicts
            this.subsistenceAllowanceDicts = subsistenceAllowanceDicts
            this.isFocusGroupsDicts = isFocusGroupsDicts
            this.endowmentInsuranceDicts = endowmentInsuranceDicts
            this.disabilityTypeDixts = disabilityTypeDixts
            this.nowMilitaryServiceDicts = nowMilitaryServiceDicts
            this.emptyNestDicts = emptyNestDicts
            this.dataForm.id = id || 0
            if(this.dataForm.id){
                this.$http({
                url: `/dg-ic/ic/personnel-basic/info/${this.dataForm.id}`,
                method: 'get',
                params: this.$http.adornParams()
                }).then(({data})=>{
                    if(data && data.code === 0){
                        this.dataForm.roomId = data.data.roomId
                        this.dataForm.griddingId = data.data.griddingId
                        this.dataForm.householderName = data.data.householderName
                        this.dataForm.houseAddress = data.data.houseAddress
                        this.dataForm.contactPhone = data.data.contactPhone
                        this.dataForm.landlordName = data.data.landlordName
                        this.dataForm.landlordPhone = data.data.landlordPhone
                        this.dataForm.realName = data.data.realName
                        this.dataForm.relationsWithHouseholds =  String(data.data.relationsWithHouseholds)
                        this.dataForm.gender = String(data.data.gender)
                        this.dataForm.nation = String(data.data.nation)
                        this.dataForm.birthdate = data.data.birthdate
                        this.dataForm.maritalStatus = String(data.data.maritalStatus)
                        this.dataForm.weddingDay = data.data.weddingDay
                        this.dataForm.accountProperties = String(data.data.accountProperties)
                        this.dataForm.domicileAddress = data.data.domicileAddress
                        this.dataForm.identityCard = data.data.identityCard
                        this.dataForm.healthCondition = String(data.data.healthCondition)
                        this.dataForm.educationDegree = String(data.data.educationDegree)
                        this.dataForm.isOnly = String(data.data.isOnly)
                        this.dataForm.occupation = String(data.data.occupation)
                        this.dataForm.workUnit = data.data.workUnit
                        this.dataForm.isPartyMember = String(data.data.isPartyMember)
                        this.dataForm.isSubsistenceAllowance = String(data.data.isSubsistenceAllowance)
                        this.dataForm.isFocusGroups = String(data.data.isFocusGroups)
                        this.dataForm.isEndowmentInsurance = String(data.data.isEndowmentInsurance)
                        this.dataForm.disabilityType = String(data.data.disabilityType)
                        this.dataForm.disabilityNumber = data.data.disabilityNumber
                        this.dataForm.isNowMilitaryService = String(data.data.isNowMilitaryService)
                        this.dataForm.isEmptyNest = String(data.data.isEmptyNest)
                        this.dataForm.isWithDoor = String(data.data.isWithDoor)
                        this.dataForm.letDate = data.data.letDate
                    }
                })
            }
        },

        // 基础信息的表单提交
        dataFormSubmit(){
            this.$refs['dataForm'].validate((validate)=>{
                if(validate){
                    this.$http({
                        url: `/dg-ic/ic/personnel-basic/${!this.dataForm.id ? 'save' : 'update'}`,
                        method: 'post',
                        data: this.$http.adornData({
                            'id':this.dataForm.id || undefined,
                            'roomId': this.roomAddress[this.roomAddress.length-1],
                            'griddingId': this.dataForm.griddingId,
                            'householderName': this.dataForm.householderName,
                            'houseAddress': this.dataForm.houseAddress,
                            'contactPhone': this.dataForm.contactPhone,
                            'landlordName': this.dataForm.landlordName,
                            'landlordPhone': this.dataForm.landlordPhone,
                            'realName': this.dataForm.realName,
                            'relationsWithHouseholds': this.dataForm.relationsWithHouseholds,
                            'gender': this.dataForm.gender,
                            'nation': this.dataForm.nation,
                            'birthdate': this.dataForm.birthdate,
                            'maritalStatus': this.dataForm.maritalStatus,
                            'weddingDay': this.dataForm.weddingDay,
                            'accountProperties': this.dataForm.accountProperties,
                            'domicileAddress': this.dataForm.domicileAddress,
                            'identityCard': this.dataForm.identityCard,
                            'healthCondition': this.dataForm.healthCondition,
                            'educationDegree': this.dataForm.educationDegree,
                            'isOnly': this.dataForm.isOnly,
                            'occupation': this.dataForm.occupation,
                            'workUnit': this.dataForm.workUnit,
                            'isPartyMember': this.dataForm.isPartyMember,
                            'isSubsistenceAllowance': this.dataForm.isSubsistenceAllowance,
                            'isFocusGroups': this.dataForm.isFocusGroups,
                            'isEndowmentInsurance': this.dataForm.isEndowmentInsurance,
                            'disabilityType': this.dataForm.disabilityType,
                            'disabilityNumber': this.dataForm.disabilityNumber,
                            'isNowMilitaryService': this.dataForm.isNowMilitaryService,
                            'isEmptyNest': this.dataForm.isEmptyNest,
                            'isWithDoor': this.dataForm.isWithDoor,
                            'letDate': this.dataForm.letDate,
                            'createBy': this.$store.state.user.id,
                            'updateBy': this.$store.state.user.id,
                            'avatar': this.dataForm.image
                        })
                    }).then(({data})=>{
                        if(data && data.code === 0){
                            this.$message({
                            message: '操作成功',
                            type: 'success',
                            duration: 1500,
                            onClose: () => {
                                this.visible = false
                                // 触发父组件的自定义事件
                                this.$emit('refreshDataList')
                                this.$refs[`dataForm`].resetFields()
                                let obj = {}
                                obj.stopPropagation = () =>{}
                                this.$refs.room.clearValue(obj)
                            }
                        })
                        }else{
                            this.$message.error(data.msg)
                        }
                    })
                }
            })
        },
        // 基础信息关闭
        callOf(){
            this.visible = false
            this.$refs[`dataForm`].resetFields()
            let obj = {}
            obj.stopPropagation = () =>{}
            this.$refs.room.clearValue(obj)
            this.dataForm.image = ''
        },
        // 男方/女方
        getWomanMan(){
            this.$http({
            url: 'dg-ic/ic/dict/type/woman_type',
            method: 'get'
            }).then(({data})=>{
                if(data && data.code === 0){
                this.womanManDicts = data.data;
                // for(let i = 0; i < data.data.length; i++){
                //     this.householdDictType[data.data[i].value] = data.data[i].label;
                // };
                }
            })
        },
        // 血缘关系
        getKinship(){
            this.$http({
            url: 'dg-ic/ic/dict/type/kinship_type',
            method: 'get'
            }).then(({data})=>{
                if(data && data.code === 0){
                this.kinshipDicts = data.data;
                }
            })
        },
        getGenner(){
            this.$http({
            url: 'dg-standard-info/common/dgbasedictionary/dictlist/sex',
            method: 'get'
            }).then(({data})=>{
                if(data && data.code === 0){
                this.genderOptions = data.dictList;
                }
            })
        },
        getNation(){
            this.$http({
            url: 'dg-standard-info/common/dgbasedictionary/dictlist/nation',
            method: 'get'
            }).then(({data})=>{
                if(data && data.code === 0){
                this.nationOptions = data.dictList;
                }
            })
        },



    }
}
</script>
